﻿@page "/So/SaleReturnDetail/Details"
@using nERP.ViewModel.So.SaleReturnDetailVMs
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<div>
    <ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
        <Row ItemsPerRow="ItemsPerRow.Three" RowType="RowType.Normal">
            <Display @bind-Value="@Model.Entity.Seq" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.SaleReturnId" ShowLabel="true" Lookup="AllSaleReturns" />
            <Display @bind-Value="@Model.Entity.SaleReturnDetailCode" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.SaleOutWarehouseDetailId" ShowLabel="true" Lookup="AllSaleOutWarehouseDetails" />
            <Display @bind-Value="@Model.Entity.SaleId" ShowLabel="true" Lookup="AllSales" />
            <Display @bind-Value="@Model.Entity.SaleDetailId" ShowLabel="true" Lookup="AllSaleDetails" />
            <Display @bind-Value="@Model.Entity.GoodsId" ShowLabel="true" Lookup="AllGoodss" />
            <Display @bind-Value="@Model.Entity.GoodsName" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.GoodsSpec" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.GoodsUnit" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.ReturnNumber" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.UnitPrice" ShowLabel="true" FormatString="0.##" />
            <Display @bind-Value="@Model.Entity.TotalPrice" ShowLabel="true" FormatString="0.##" />
            <Display @bind-Value="@Model.Entity.DiscountPrice" ShowLabel="true" FormatString="0.##" />
            <Display @bind-Value="@Model.Entity.TaxRate" ShowLabel="true" FormatString="0.##" />
            <Display @bind-Value="@Model.Entity.TaxUnitPrice" ShowLabel="true"  FormatString="0.##" />
            <Display @bind-Value="@Model.Entity.TaxPrice" ShowLabel="true" FormatString="0.##" />
            <Display @bind-Value="@Model.Entity.TotalTaxPrice" ShowLabel="true" FormatString="0.##" />
            <Display @bind-Value="@Model.Entity.Status" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.Remark" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.CreateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
            <Display @bind-Value="@Model.Entity.UpdateTime" ShowLabel="true" FormatString="yyyy-MM-dd HH:mm:ss" />
            <Display @bind-Value="@Model.Entity.CreateBy" ShowLabel="true" />
            <Display @bind-Value="@Model.Entity.UpdateBy" ShowLabel="true" />
        </Row>

        <div class="modal-footer table-modal-footer">
            <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]" />
        </div>

    </ValidateForm>

</div>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private SaleReturnDetailVM Model = new SaleReturnDetailVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {


        await PostsForm(vform, "/api/So/SaleReturnDetail/Edit", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }

    private List<SelectedItem> AllSaleReturns = new List<SelectedItem>();
    private List<SelectedItem> AllSaleOutWarehouseDetails = new List<SelectedItem>();
    private List<SelectedItem> AllSales = new List<SelectedItem>();
    private List<SelectedItem> AllSaleDetails = new List<SelectedItem>();
    private List<SelectedItem> AllGoodss = new List<SelectedItem>();
    protected override async Task OnInitializedAsync()
    {


        AllSaleReturns = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSaleReturns");
        AllSaleReturns.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSaleOutWarehouseDetails = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSaleOutWarehouseDetails");
        AllSaleOutWarehouseDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSales = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSales");
        AllSales.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllSaleDetails = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetSaleDetails");
        AllSaleDetails.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        AllGoodss = await WtmBlazor.Api.CallItemsApi("/api/So/SaleReturnDetail/GetGoodss");
        AllGoodss.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"], Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<SaleReturnDetailVM>($"/api/So/SaleReturnDetail/{id}");
            Model = rv.Data;
        }

        await base.OnInitializedAsync();
    }
}
